package com.example.controller;

import com.example.common.Result;
import com.example.entity.Imgadv;
import com.example.service.ImgadvService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 轮播图(Imgadv)表控制层
 */
@CrossOrigin
@RestController
public class ImgadvController {
    
    @Resource
    private ImgadvService imgadvService;

    // 信息列表
    @ResponseBody
    @RequestMapping("imgadvList")
    public Result imgadvList(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                            @RequestParam(defaultValue = "1", value = "pageSize") Integer pageSize,
                            HttpServletRequest request) {
        String key = request.getParameter("key");
        PageInfo<Imgadv> pageInfo = imgadvService.getImgadvList(pageNum, pageSize, key);
        return Result.success(pageInfo);
    }

    // 添加或编辑信息
    @ResponseBody
    @RequestMapping("imgadvAdd")
    public Result imgadvAdd(Imgadv imgadv, HttpServletRequest request) {
        imgadvService.saveOrUpdate(imgadv);
        return Result.success();
    }

    // 删除信息
    @ResponseBody
    @RequestMapping("imgadvDel")
    public Result imgadvDel(int id, HttpServletRequest request) {
        imgadvService.deleteImgadv(id);
        return Result.success();
    }

    // 批量删除信息
    @ResponseBody
    @RequestMapping("imgadvDeleteAll")
    public Result typeDeleteAll(HttpServletRequest request) {
        String vals = request.getParameter("vals");
        imgadvService.batchDeleteImgadv(vals);
        return Result.success();
    }
}

